******************************************************
**** Group Size and Matching Protocol in Contests ****
******************************************************

clear

** Treatment 1 = Partner3 with Group Info only (NOT IN PAPER) **
** Treatment 2 = Stranger3 with Group Info only (NOT IN PAPER) **
** Treatment 3 = Partner2 **
** Treatment 4 = Stranger2 **
** Treatment 5 = Partner3 Individual Info **
** Treatment 6 = Stranger3 Individual Info **

cd "SET FOLDER PATH WHERE DATA FILE IS LOCATED"

set more off


*****************
**** Table 1 ****
*****************

** Table 1 is a summary of our treatments and does not use data **


*****************
**** Table 2 ****
*****************
** Look at mean over ALL individuals - since there are no independent groups in the Strangers treatment **
clear
use PS-final.dta

collapse (mean) bid, by(treatment id period)
collapse (mean) bid, by(treatment id)

table treatment, contents(n bid mean bid sd bid)







******************
**** Figure 1 ****
******************

****** Graph by block ******
clear
use PS-final.dta

collapse (mean) bid, by(treatment session id block)

collapse (mean) bid, by(treatment id block)

collapse (mean) bid, by(treatment block)

generate bidpartner2 = bid if treatment==3
generate bidstranger2 = bid if treatment==4

generate bidpartner3ind = bid if treatment==5
generate bidstranger3ind = bid if treatment==6

line bidpartner2 bidstranger2 bidpartner3ind bidstranger3ind block, yline(40) yline(45) ylabel(35(5)70)


*** Graph over bid range ***
clear
use PS-final.dta

collapse (mean) bid, by(treatment id period)
collapse (mean) bid, by(treatment id)

generate bidpartner2 = bid if treatment==3
generate bidstranger2 = bid if treatment==4

generate bidpartner3ind = bid if treatment==5
generate bidstranger3ind = bid if treatment==6


generate bidbin = .
replace bidbin = 20 if bid<=20
replace bidbin = 40 if bid>20 & bid<=40
replace bidbin = 60 if bid>40 & bid<=60
replace bidbin = 80 if bid>60 & bid<=80
replace bidbin = 100 if bid>80 & bid<=100
replace bidbin = 120 if bid>100 & bid<=120
replace bidbin = 140 if bid>120 & bid<=140
replace bidbin = 160 if bid>140 & bid<=160
replace bidbin = 180 if bid>160

*** 1. Brute force method **
** bysort treatment: tab bidbin 
** Took the data from this table - the columns for percentages **
** Pasted in Excel - copied back into Stata **
** Saved data as BidDistnPercentage.dta **
** Then using this SMALL data set: "graph bar partner stranger, over(bid)" **
** Not ideal....but it works....Thanks to Subho for suggesting this very direct option **

*** The one below works!! Finally, good to have this done within Stata using the original dataset itself. ***
collapse (count) bidpartner2 bidstranger2 bidpartner3ind bidstranger3ind, by(bidbin)

generate partner2 = (bidpartner2/54)*100
generate stranger2 = (bidstranger2/54)*100

generate partner3ind = (bidpartner3ind/54)*100 
generate stranger3ind = (bidstranger3ind/54)*100

graph bar partner2 stranger2 partner3ind stranger3ind, over(bidbin)








*****************
**** Table 3 ****
*****************
****** Testing for overbidding *******
** Look at mean over ALL individuals - since there are no independent groups in the Strangers treatment **
clear
use PS-final.dta
xtset id period

* Extent of overbidding *
bysort id: generate devfromeqbm = bid - equilibrium 

vcemway xtreg devfromeqbm stranger3ind if treatment==5|treatment==6, re cluster(session id)
vcemway xtreg devfromeqbm stranger2 if treatment==3|treatment==4, re cluster(session id)
vcemway xtreg devfromeqbm size2 if treatment==5|treatment==3, re cluster(session id)
vcemway xtreg devfromeqbm size2 if treatment==6|treatment==4, re cluster(session id)








*****************
**** Table 4 ****
*****************
clear
use PS-final.dta

xtset id period

generate lagbid = l.bid
generate lagwin = l.win
generate lagothersbid = l.othersbid

set more off
eststo clear
eststo: vcemway xtmixed bid stranger l.bid l.win l.othersbid period egrisky female age if treatment==5|treatment==6, cluster(session id)
eststo: vcemway xtmixed bid stranger l.bid l.win l.othersbid period egrisky female age if treatment==3|treatment==4, cluster(session id)
eststo: vcemway xtmixed bid size2 l.bid l.win l.othersbid period egrisky female age if treatment==3|treatment==5, cluster(session id)
eststo: vcemway xtmixed bid size2 l.bid l.win l.othersbid period egrisky female age if treatment==6|treatment==4, cluster(session id)
esttab using table4.rtf, replace se label mtitles("N=3 (Ind Info)" "N=2" "Partner" "Stranger") star(* 0.10 ** 0.05 *** 0.01)
eststo clear










*****************
**** Table 5 ****
*****************
** Look at mean over ALL individuals - since there are no independent groups in the Strangers treatment **
clear
use PS-final.dta

collapse (mean) relbid2, by(treatment id period)
collapse (mean) relbid2, by(treatment id)

table treatment, contents(n relbid2 mean relbid2 sd relbid2)








*****************
**** Table 6 ****
*****************
clear
use PS-final.dta

xtset id period

generate lagbid = l.bid
generate lagwin = l.win
generate lagothersbid = l.othersbid

set more off
eststo clear
eststo: vcemway xtmixed relbid2 stranger l.bid l.win l.othersbid period egrisky female age if treatment==5|treatment==6, cluster(session id)
eststo: vcemway xtmixed relbid2 stranger l.bid l.win l.othersbid period egrisky female age if treatment==3|treatment==4, cluster(session id)
eststo: vcemway xtmixed relbid2 size2 l.bid l.win l.othersbid period egrisky female age if treatment==3|treatment==5, cluster(session id)
eststo: vcemway xtmixed relbid2 size2 l.bid l.win l.othersbid period egrisky female age if treatment==6|treatment==4, cluster(session id)
esttab using table6.rtf, replace se label mtitles("N=3 (Ind Info)" "N=2" "Partner" "Stranger") star(* 0.10 ** 0.05 *** 0.01)
eststo clear










*****************************
**** Table 7 and Table 8 ****
*****************************
clear
use PS-final.dta

** Measure 1 - Get the sd of each individual's bids over all 25 periods **
collapse (sd) bid, by(treatment session id)

** Treatment 3 = Partner2 **
** Treatment 4 = Stranger2 **
** Treatment 5 = Partner3 Individual Info **
** Treatment 6 = Stranger3 Individual Info **

generate groupsize = 3
replace groupsize = 2 if treatment==3|treatment==4

generate size2 = 0
replace size2 = 1 if groupsize==2

generate stranger = 0
replace stranger = 1 if treatment==4|treatment==6

generate partner2 = 0
replace partner2 = 1 if treatment==3

generate stranger2 = 0
replace stranger2 = 1 if treatment==4

generate partner3ind = 0
replace partner3ind = 1 if treatment==5

generate stranger3ind = 0
replace stranger3ind = 1 if treatment==6

** Column 1 of Table 7: Difference between group size within same matching protocol **
regress bid size2 if treatment==5|treatment==3, cluster(session)
regress bid size2 if treatment==6|treatment==4, cluster(session)

** Column 1 of Table 8: Difference across matching protocol within same group size **
regress bid stranger3ind if treatment==5|treatment==6, cluster(session)
regress bid stranger2 if treatment==3|treatment==4, cluster(session)




** Measure 2 - Get the sd of all individual's bids in EACH period **
clear
use PS-final.dta

collapse (sd) bid, by(treatment session period)

** Treatment 3 = Partner2 **
** Treatment 4 = Stranger2 **
** Treatment 5 = Partner3 Individual Info **
** Treatment 6 = Stranger3 Individual Info **

generate groupsize = 3
replace groupsize = 2 if treatment==3|treatment==4

generate size2 = 0
replace size2 = 1 if groupsize==2

generate stranger = 0
replace stranger = 1 if treatment==4|treatment==6

generate partner2 = 0
replace partner2 = 1 if treatment==3

generate stranger2 = 0
replace stranger2 = 1 if treatment==4

generate partner3ind = 0
replace partner3ind = 1 if treatment==5

generate stranger3ind = 0
replace stranger3ind = 1 if treatment==6

xtset session period

** Column 2 of Table 7: Difference between group size within same matching protocol **
xtreg bid size2 period if treatment==5|treatment==3, re cluster(session)
xtreg bid size2 period if treatment==6|treatment==4, re cluster(session)


** Column 2 of Table 8: Difference across matching protocol within same group size **
xtreg bid stranger3ind period if treatment==5|treatment==6, re cluster(session)
xtreg bid stranger2 period if treatment==3|treatment==4, re cluster(session)
